package com.marce.remis.flexClient.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.marce.remis.flexClient.events.AbstractEvent;
	
	import mx.controls.Alert;
	import mx.resources.IResourceManager;
	import mx.resources.ResourceManager;
	import mx.rpc.IResponder;

	public class AbstractCommand implements ICommand, IResponder
	{
		protected var evento:AbstractEvent;
		public function execute(event:CairngormEvent):void
		{
			evento = event as AbstractEvent;
			executeCommand(evento);
		}
		
		public function executeCommand(evento:AbstractEvent):void{
			
		}
		
		public function result(data:Object):void
		{
			onResult(data.result);
			executeSuccessFunction();
		}
		
		public function onResult(data:Object):void{
			
		}
		
		public function fault(info:Object):void
		{
			var resourceManager:IResourceManager = ResourceManager.getInstance();
			Alert.show(resourceManager.getString("recursos","global.error.tx"),resourceManager.getString("recursos","global.error"));

		}
		
		protected function executeSuccessFunction():void{
			if(evento.successFunction!=null){
				if(evento.successFunctionAttribute)
					evento.successFunction(evento.successFunctionAttribute);
				else
					evento.successFunction();
			}
		}
		
	}
}